package com.xm.cloud.rabbitmq.mq;

import com.xm.rabbitmq.dto.UserEvent;
import com.xm.rabbitmq.dto.mq.pipeline.UserEventPipeline;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 小木
 * @date 2021/4/20
 * @desc
 */
@Component
@EnableBinding(UserEventPipeline.class)
public class UserEventProducer {

    private final Logger logger = LoggerFactory.getLogger(UserEventProducer.class);

    @Resource(name = UserEventPipeline.SEND)
    private MessageChannel sendChannel;

    public void send(UserEvent userEvent) {
        Message<UserEvent> message = MessageBuilder.withPayload(userEvent).build();
        logger.info("============= Send UserEventProducer: {}", userEvent);
        sendChannel.send(message);
    }

}
